/*
 * Created on Oct 28, 2004
 *
 */
package ModuleBuilder.UI.tree;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.*; 

import ModuleBuilder.ModuleBuilderMain;
import ModuleBuilder.model.ScenarioDetailModel;

/**
 * @author Milton  Soong
 *
 */
public class ScenarioDetailPanel extends JPanel {
	
	private JLabel nameLabel;
	private JTextField nameTextField;
	private JLabel mapScaleLabel;
	private JTextField mapScaleTextField;
	private JLabel distanceUnitLabel;
	private JTextField distanceUnitTextField;
	
	private JLabel notesLabel;
	private JTextArea notesArea;
	private ScenarioDetailModel model;	// the Current model being operated at.	
	
	public ScenarioDetailPanel() {
		
		nameLabel = new JLabel("Scenario Name:");
		mapScaleLabel = new JLabel("Map Scale");
		distanceUnitLabel = new JLabel("Distance Unit");
		notesLabel = new JLabel("Scenario Notes");
		
		nameTextField = new JTextField();
		mapScaleTextField = new JTextField();
		distanceUnitTextField = new JTextField();
		notesArea = new JTextArea();
		notesArea.setLineWrap(true);
		
		// now do the layout
		//this.setLayout(new GridLayout(0,2));
		JPanel sdPanel = new JPanel();
		sdPanel.setLayout(new BoxLayout(sdPanel, BoxLayout.PAGE_AXIS));
		sdPanel.add(nameLabel);
		sdPanel.add(nameTextField);
		nameLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		nameTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);

		JPanel msPanel = new JPanel();
		msPanel.setLayout(new BoxLayout(msPanel, BoxLayout.PAGE_AXIS));
		msPanel.add(mapScaleLabel);
		msPanel.add(mapScaleTextField);
		mapScaleLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		mapScaleTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);

		
		JPanel duPanel = new JPanel();
		duPanel.setLayout(new BoxLayout(duPanel, BoxLayout.PAGE_AXIS));
		duPanel.add(distanceUnitLabel);
		duPanel.add(distanceUnitTextField);
		distanceUnitLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		distanceUnitTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);

		
		JPanel notePanel = new JPanel();
		notePanel.setLayout(new BoxLayout(notePanel, BoxLayout.PAGE_AXIS));
		notePanel.add(notesLabel);
		JScrollPane noteScrollPane = 
		    new JScrollPane(notesArea,
		                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
		                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		notesArea.setEditable(true);
		notePanel.add(noteScrollPane);
		notesLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		noteScrollPane.setAlignmentX(JComponent.LEFT_ALIGNMENT);

		

		// now need to set some size limitations to the components
		Dimension d = nameTextField.getPreferredSize();
		d.width = 200;
		nameTextField.setMinimumSize(d);
		nameTextField.setPreferredSize(d);
		nameTextField.setMaximumSize(d);

		d = mapScaleTextField.getPreferredSize();
		d.width = 200;
		mapScaleTextField.setMinimumSize(d);
		mapScaleTextField.setPreferredSize(d);
		mapScaleTextField.setMaximumSize(d);

		d = distanceUnitTextField.getPreferredSize();
		d.width = 200;
		distanceUnitTextField.setMinimumSize(d);
		distanceUnitTextField.setPreferredSize(d);
		distanceUnitTextField.setMaximumSize(d);
		
		// overall layout
		this.setLayout( new BoxLayout(this, BoxLayout.PAGE_AXIS));
		sdPanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		msPanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		duPanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		notePanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		
		this.add(sdPanel);
		this.add(msPanel);
		this.add(duPanel);
		this.add(notePanel);
		
		Color bc = this.getBackground();
		this.setBorder(BorderFactory.createMatteBorder(10,10,10,10, bc));

	}

	/**
	 * @return Returns the distanceUnitTextField.
	 */
	public JTextField getDistanceUnitTextField() {
		return distanceUnitTextField;
	}
	/**
	 * @param distanceUnitTextField The distanceUnitTextField to set.
	 */
	public void setDistanceUnitTextField(String t) {
		this.distanceUnitTextField.setText(t);
	}
	/**
	 * @return Returns the mapScaleTextField.
	 */
	public JTextField getMapScaleTextField() {
		return mapScaleTextField;
	}
	/**
	 * @param mapScaleTextField The mapScaleTextField to set.
	 */
	public void setMapScaleTextField(String t) {
		this.mapScaleTextField.setText(t);
	}
	/**
	 * @return Returns the model.
	 */
	public ScenarioDetailModel getModel() {
		return model;
	}
	/**
	 * @param model The model to set.
	 */
	public void setModel(ScenarioDetailModel model) {
		this.model = model;
	}
	/**
	 * @return Returns the nameTextField.
	 */
	public JTextField getNameTextField() {
		return nameTextField;
	}
	/**
	 * @param nameTextField The nameTextField to set.
	 */
	public void setNameTextField(String t) {
		this.nameTextField.setText(t);
	}
	/**
	 * @return Returns the notesArea.
	 */
	public JTextArea getNotesArea() {
		return notesArea;
	}
	/**
	 * @param notesArea The notesArea to set.
	 */
	public void setNotesArea(Document docIn) {
		if ( docIn != null ){
			this.notesArea.setDocument(docIn);
		}
	}
	
	public void disableEditable() {
		this.nameTextField.setEditable(false);
		this.mapScaleTextField.setEditable(false);
		this.distanceUnitTextField.setEditable(false);
		this.notesArea.setEditable(false);
		
	}
}
